package com.bianguo.android.iocdemo.view.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.bianguo.android.injectlibrary.annotations.ContentView;
import com.bianguo.android.injectlibrary.annotations.InjectView;
import com.bianguo.android.iocdemo.R;
import com.bianguo.android.iocdemo.view.widget.MoveView;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

@ContentView(R.layout.activity_move)
public class MoveActivity extends BaseActivity implements MoveView.OnMoveListener {

    @InjectView(R.id.move_view)
    MoveView moveView;
    @InjectView(R.id.move_toolbar)
    Toolbar mToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(mToolbar);
        moveView.setOnMoveListener(this);
    }

    private void setTitleCenter(Toolbar mToolbar) {
        Class<? extends Toolbar> clazz = mToolbar.getClass();
        try {
            Field field = clazz.getDeclaredField("mTitleTextView");
            field.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_music, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @SuppressLint("RestrictedApi")
    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        if (menu != null) {
            if (menu instanceof MenuBuilder) {
                MenuBuilder menuBuilder = (MenuBuilder) menu;
                menuBuilder.setOptionalIconsVisible(true);
            }
        }
        return super.onMenuOpened(featureId, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            case R.id.music_search:
                Toast.makeText(this, "click search", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.music_help:
                Toast.makeText(this, "click help", Toast.LENGTH_SHORT).show();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void touchOutside() {
        Toast.makeText(this, "touch outside", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onMove() {

    }
}
